<template>
  <div class="common-table">
    <el-table :data="tableData" height="600px" stripe>
      <!--接受外部数据以及设置高度,设置样式为条纹-->
      <el-table-column
        show-overflow-tooltip
        v-for="item in tableLabel"
        :key="item.prop"
        :label="item.label"
        :width="item.width ? item.width : 125"
      >
        <!--列内容溢出后的部分用tooltip显示-->
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
      <!--操作列-->
      <el-table-column label="操作" min-width="180">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "CommonTable",
  props: {
    tableData: Array, //表格数据
    tableLabel: Array, //列数据
  },
  methods: {
    handleEdit(row) {
      this.$emit("edit", row); //向父组件通信传行数据
    },
    handleDelete(row) {
      this.$emit("delete", row);
    },
  },
};
</script>

<style scoped>
.common-table {
  height: calc(100% - 62px); /*计算高度 */
  background-color: #fff;
  position: relative;
}
</style>
